home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
libs
/
knowhow4
/
khds.doc
< prev
next >
Wrap
Text File
|
1994-05-30
|
18KB
|
626 lines
KNOW-HOW.DataShell
(Paradox Engine Shell)
(C) Stepan S.Vartanov, 1994
KNOW-HOW.DATASHELL is a Borland Paradox Engine 3.01 shell.
It consists of 3 parts.
1. Abstract table representation. Viewer - Editor for any tables (DB,
Spreadsheet and so on) could be derived from it by overloading the
virtual field access functions.
2. Paradox tables viewer - editor - ask manager (as one of (1)).
3. QBE Manager (window - independent) for Paradox tables.
ATTENTION !!! First of all it is tables representation, Paradox
Engine Shell is only one of possible adaptations.
Tested on Borland C++ 3.x.
//////////////////////////////////////////////////////////////////////////
Field incapsulation (types are listed in FLDTYPE.H, this set /
may be expanded): /
enum KH_FIELD_TYPE { KH_NUMBER = 1, KH_STRING = 2,
KH_DATE = 4, KH_SHORT = 8, KH_MONEY = 16,
KH_BLOB = 32, KH_ALL = 63 };
PXFIELD.H:
#include <pxengine.h>
#include "khpxeerr.h"
#include "fldtype.h"
struct KH_PXFLD
{
KH_FIELD_TYPE type; // Field type
char* str; // Data
double n;
long date;
short sh;
KH_PXFLD(double f) { type = KH_NUMBER; n = f; }
KH_PXFLD(long f) { type = KH_DATE; date = f; }
KH_PXFLD(short f) { type = KH_SHORT; sh = f; }
KH_PXFLD(char* buf) { type = KH_STRING, str = buf; }
};
File "khpxeerr.h" registers few additional error messages:
char* KH_ERRORS[] = {
"",
"No checked fields in querry",
"Table is not linked with others. Use EXAMPLE",
"Incompatible field types with the same EXAMPLE"
You could not querry BLOBS (DataShell could not, YOU could):
"Condition on BLOB field",
"Example on BLOB field"
};
Table incapsulation, PX_TABLE.H.
class AskManager;
class PrintManager;
class KH_PXTable
{
protected:
char* fileName; // Table Name
TABLEHANDLE tblHandle; // Table Handle
RECORDHANDLE recHandle; // Record Handle
FIELDHANDLE fldHandle; // Field Handle
RECORDNUMBER current; // Current record number
RECORDNUMBER nRecords; // Total length
int nFlds; // Fields in table
public:
KH_PXTable(char* fName, int idx = 0, // Index, simple or complex
If new table created:
int fNo = 0,
char** fields = NULL,
char** types = NULL);
~KH_PXTable();
// Service
TABLEHANDLE getTblHandle() { return tblHandle; }
RECORDHANDLE getRecHandle() { return recHandle; }
FIELDHANDLE getFldHandle() { return fldHandle; }
void setFld(int f) { fldHandle = f; }
void setRec(RECORDHANDLE rec) { recHandle = rec; }
int getField(KH_PXFLD* ret);
int putField(KH_PXFLD* f);
Is querry correct? Return 0 (FALSE), 1 (TRUE).
int testQuerry(char** shablon);
Convert field to string (char*).
KH_FIELD_TYPE TranslateField(char* buf);
Single table querry. Use shablon - set of field querries. Methods of
comparing could be overloaded in child class.
int Find(char** shablon);
virtual int Compare(char* shab, char* field); // Strings
virtual int Compare(char* shab, double field); // Numbers
virtual int Compare(char* shab, long field); // Date and Long
virtual int Compare(char* shab, short field); // Short
friend class KH_AskManager;
friend class KH_ReportManager;
};
Example.
#include <iostream.h>
#include <dos.h>
/////////////////////
void main()
{
if(PXInit() != PXSUCCESS)
return;
KH_PXTable table("demo.db");
char* shablon[] = { "", "", "", "Ivanov", "", "", "", "", "" };
char buf[255];
int eot;
while(table.Find(shablon) == 1)
{
for(int i = 1; i < 5; i++)
{
table.setFld(i);
table.TranslateField(buf);
cout << buf;
}
cout << "\n";
}
PXExit();
}
AskManager class work with multy tables querries. To link tables
EXAMPLES are used.
STRTABLE.H:
struct KH_STRTABLE
{
int used;
int total;
char** strings;
KH_STRTABLE(int n, char** str = NULL);
~KH_STRTABLE();
int add(char* str);
char* operator [](int n) { return strings[n]; }
};
KHQUERRY.H incapsulate querry (examples, checks, ...):
struct KH_QUERRY
{
KH_STRTABLE* querry; // Conditions
int* querryNumbers; // Not-empty fields in querry
KH_STRTABLE* examples; // Example variables
int* exampleNumbers; // And numbers
int* checkedFields; // Include this fields to ANSWER table
KH_QUERRY(char** querries, char** examples, char* checkers,
int numOfColumnsInTable);
KH_QUERRY(KH_STRTABLE* querry, KH_STRTABLE* examples,
char* checkers, int numOfColumnsInTable)
{ KH_QUERRY(querry->strings, examples->strings, checkers,
numOfColumnsInTable); }
~KH_QUERRY();
};
ASK_MAN.H:
extern int indexNo; // The only reason - error in Paradox Engine
class KH_AskManager
{
protected:
KH_PXTable** tables; // List of tables
KH_QUERRY** querryList; // List of querries
KH_PXTable* workTable; // Intermadiate results
KH_PXTable* answerTable; // Result
int numberOfTables; // Total number of tables
public:
KH_AskManager(char** tableNames, KH_QUERRY** querries,
int numberOfTables);
~KH_AskManager();
Build ANSWER.DB containing all fields from all tables:
int createAnswerTable(int nOT);
checkQuerry() - is the querry correct
/*virtual*/ int KH_AskManager::checkQuerry();
Service:
......................................................
int processSingleTable();
int processMultipleTables();
int process();
.......................................................
};
Example:
1.
#include <iostream.h>
#include <time.h>
/////////////////////
void main()
{
if(PXInit() != PXSUCCESS)
return;
char* tableNames[] = { "demo.db" };
char* q[] = { "", "", "", "", "", "", "", "", "" }; // Querries
char* e[] = { "", "", "", "", "", "", "", "", "" }; // Examples
char* c = "\2\2\2\2\2\2\2\2\2\2\0"; // Checkers
KH_QUERRY* querry1 = new KH_QUERRY(q, e, c, 5); // Build querry
KH_QUERRY* querries[2]; // Build querry list
querries[0] = querry1;
KH_AskManager* ask = new KH_AskManager(tableNames, querries, 1);
ask->process();
////////////
Next code print table contents on screen:
KH_PXTable table("answer.db");
char* shablon[] = { "", "", "", "", "", "", "", "", "", "", "" };
char buf[255];
int eot;
while(table.Find(shablon) == 1)
{
for(int i = 2; i < 5; i++)
{
table.setFld(i);
table.TranslateField(buf);
cout << buf << '\t';
}
cout << "\n";
}
delete ask;
delete querry1;
unlink("answer.db");
PXExit();
}
2. 3 tables:
void main()
{
if(PXInit() != PXSUCCESS)
return;
indexNo = 0; // Attention!!! Absolutely necessary!!!
char* tableNames[] = { "demo.db", "demo.db", "demo.db" };
char* q[] = { "", "", "", "", "", "", "", "", "" }; // Querries
char* e[] = { "", "", "X", "", "", "", "", "", "" }; // Examples
char* c = "\2\2\2\2\2\2\2\2\2\2\0"; // Checkers
KH_QUERRY* querry1 = new KH_QUERRY(q, e, c, 5); // Build querry
KH_QUERRY* querries[3]; // Querry list
querries[0] = querry1;
querries[1] = querry1;
querries[2] = querry1;
KH_AskManager* ask = new KH_AskManager(tableNames, querries, 3);
ask->process(); // Process querry, get ANSWER table
View the result.
KH_PXTable table("answer.db");
char* shablon[] = { "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "",
"", "", "", "" };
char buf[255];
int eot;
long l = 0;
while(table.Find(shablon) == 1)
{
for(int i = 1; i < 16; i++)
{
table.setFld(i);
table.TranslateField(buf);
cout << i << ": " << buf << "\n";
}
cout << "<<<<<<<<<<<<< RECORD " << l << " >>>>>>>>>>>>>>>>\n";
l++;
}
delete ask;
delete querry1;
unlink("answer.db");
PXExit();
}
3. BLOBs are not standart and we do not know, how to process them
in concrete situation. We use showBLOB() function call, and user
must overload it if necessary.
void main() // Add operations on BLOB fields
{
// Init PARADOX ENGINE
if(PXInit() != PXSUCCESS)
return;
// Process single-table querry to DEMO.DB table
char* tableNames[] = { "demo.db" }; // Table name
char* q[] = { "", "", "", "", "", "", "", "", "" }; // Querries
char* e[] = { "", "", "", "", "", "", "", "", "" }; // Examples
char* c = "\2\2\2\2\2\2\2\2\2\2\0"; // Checkers
KH_QUERRY* querry1 = new KH_QUERRY(q, e, c, 5); // Build querry
KH_QUERRY* querries[2]; // Querry list
querries[0] = querry1;
KH_AskManager* ask = new KH_AskManager(tableNames, querries, 1);
ask->process(); // Process querry, get ANSWER table
////////////
KH_PXTable table("answer.db");
char* shablon[] = { "", "", "", "", "", "", "", "", "", "", "" };
char buf[255];
char buf1[255];
int eot;
KH_PXFLD* retFld = new KH_PXFLD(buf1);
while(table.Find(shablon) == 1)
{
for(int i = 1; i < 6; i++)
{
table.setFld(i);
If BLOB - message.
if(table.TranslateField(buf) == KH_BLOB)
{
table.getField(retFld);
cout << "***************** BLOB: " << retFld->str << "\n";
}
else
cout << buf << "\n";
}
cout << "<<<<<<<<<<<<<<<<<<<<<<<<\n";
}
delete retFld;
delete ask;
delete querry1;
unlink("answer.db");
PXExit();
}
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
Interface classes of KNOW-HOW.DATASHELL
KH_TABLE.H - abstract table, not only Paradox:
#include "simple.h" // like ulong == unsigned long
class KH_TableView
{
protected:
ulong yStart; // 1st visible record
int xStart; // Left page field
int yPos; // From page top to cursor
int xPos; // From left page side
int xCurs; // Current field
ulong yCurs; // Current record
int xScreen; // Screen clip, cells
int yScreen; // -//-
int nColumns; // Columns in table, -1 - autodetect
int* iColWidth; // Column widths
int* colNumbers; // You could rotate columns
public:
KH_TableView(int width, int height, int columnsNumber = -1,
int* widthOfColumns = NULL, int* columnsOrder = NULL);
Clip area
void setWidth(int w) { xScreen = w; }
void setHeight(int h) { yScreen = h; }
Cursor move
int Left();
int Right();
int Up();
int Down();
void Home();
void End();
void PgUp();
void PgDown();
void CtrlPgUp();
void CtrlPgDown();
void PgLeft();
void PgRight();
Rotate (as CTRL-R in Paradox)
void Rotate();
Insert - remove record
virtual void insRecord() {}
virtual void delRecord() {}
For mouse jumps
void moveToCell(loc ms);
virtual long RecordNumber() { return 1L; }
virtual int getColumnNumber() { return 1; }
};
ABSTABLE.H - window - dependent abstract table.
Write access:
enum KH_TABLE_MODE { KH_EDIT_TABLE, KH_VIEW_TABLE };
class KH_AbstractTable : public KH_TableView, public Window
{
protected:
KH_TABLE_MODE mode;
public:
KH_AbstractTable(rect coordinates, char* swappingFileName = "",
char* header = "", int shadowWidthPixels = 0,
int numOfColumn = -1, int* widthsOfColumns = NULL,
int* columnsOrder = NULL,
KNOW-HOW specific:
BORDERS b_type = SHOW_BORDER,
BORDERS hdr_b_type = SHOW_BORDER,
int resizeStatus = 0, int pattern = 0, int hdr_pat = 0);
virtual void getFieldName(char* name, int n) // Field name
{ strcpy(name, "Name"); }
.............................
virtual long RecordNumber() { return 25L; }
virtual int getColumnNumber() { return 8; }
Redraw current field
virtual void showField(int xcell, int x, int y, int flag,
int field_type) {}
Field type
virtual int getFieldType(int x, int y) { return 0; }
Show object
virtual void show();
virtual void exe(int act = 0);
virtual int writeAccess() { return 0; }
Save
virtual void saveTable() {}
Edit of field
virtual void editField() {}
void showCursor(rect r, int color, int startX, int startY,
int endX, int endY);
void getItemPos(loc l, int* startX, int* startY, int* endX,
int* endY);
virtual int getFieldMaxWidth() { return 1; }
Grid
void line_table(rect r);
Search, if ask == 1 - ask for value, else use field value
virtual int searchField(int ask) { return 1; }
};
Example.
void main()
{
if(!init_KNOW_HOW())
return;
setfillstyle(SOLID_FILL, pColorSet->colors.BAK_COLOR);
bar(0, 0, getmaxx(), getmaxy());
int wid[] = { 5, 6, 7, 8, 7, 6, 5, 6, 6, 6 };
int num[] = { 1, 0, 3, 2, 4, 5, 6, 7, 8 };
KH_AbstractTable w(rect(10, 10, 50, 20), "window.pcy",
" KNOW-HOW 4.x", 6, 8, wid, num);
w.show_window();
w.exe();
w.hide();
close_KNOW_HOW();
closegraph();
}
KHPXTAB.H - Paradox table.
class KH_PX_Table : public KH_AbstractTable, public KH_PXTable
{
public:
KH_PX_Table(rect coordinates,
char* tabName,
char* fName = "",
char* h = "",
int s = 0,
BORDERS b_type = SHOW_BORDER,
BORDERS hdr_b_type = SHOW_BORDER,
int res = 0,
int hdr_pat = 0,
int fNo = 0,
char** fields = NULL,
char** types = NULL);
~KH_PX_Table();
int check_type(int type, char* string);
virtual long RecordNumber();
virtual int getColumnNumber();
virtual void getFieldName(char* name, int n);
virtual void showField(int sx, int x, int y, int flag,
int field_type);
virtual void saveTable();
virtual int writeAccess() { return 1; }
virtual void editField();
virtual int getFieldMaxWidth();
virtual void insRecord();
virtual void delRecord();
virtual int searchField(int ask);
};
Example.
void main()
{
if(!init_KNOW_HOW())
return;
if(PXInit() != PXSUCCESS)
return;
KH_PX_Table w(rect(20, 2, 78, 24), "demo.db", "window.pcy",
"", //" KNOW-HOW 4.x", 3, SHOW_BORDER, NO_BORDER, 0, 19);
w.show_window();
w.exe();
w.hide();
PXExit();
close_KNOW_HOW();
closegraph();
}
Containers. BlockT(ext)PXTable and BlockI(con)PXTable.
void main()
{
if(!init_KNOW_HOW())
return;
if(PXInit() != PXSUCCESS)
return;
BlockIPXTable w(rect(10, 2, 78, 18), "demo.db", "window.pcy",
" KNOW-HOW 4.x", 3, SHOW_BORDER, SHOW_BORDER, MOVE | RESIZE, 19,
0);
w.show_window();
w.exe();
w.hide();
PXExit();
close_KNOW_HOW();
closegraph();
}
Querries. Ask edits querry.
ASK.H
#define QUERRY_MAX_LEN 250
#define EXAMPLE_MAX_LEN 8
class Ask : public KH_AbstractTable
{
protected:
char* tableName; // Name
KH_STRTABLE* querry; // Conditions
KH_STRTABLE* examples; // Example variables
char* checkers; // Marked
KH_STRTABLE* fieldNames; // Field names
public:
Ask(rect coordinates, char* tabName, KH_STRTABLE* fields,
char* fName = "",
int s = 0, BORDERS b_type = SHOW_BORDER,
int res = 0, int pat = 0, int hdr_pat = 0);
~Ask() { delete tableName; delete querry; delete examples;
delete checkers; delete fieldNames; }
virtual void getFieldName(char* name, int n);
virtual long RecordNumber() { return 1L; }
virtual int getColumnNumber() { return nColumns; }
virtual void showField(int xcell, int x, int y, int flag,
int field_type);
virtual void show();
virtual int writeAccess() { return 1; }
virtual void saveTable() {}
virtual void editField();
virtual int searchField(int ask);
virtual int getFieldMaxWidth();
toush() function return (in global) results of edit session. See ASK.H.
virtual void touch();
};
Example.
void main()
{
if(!init_KNOW_HOW())
return;
char* s[] = { "One", "Two", "Three", "Four", "Five" };
KH_STRTABLE* fields = new KH_STRTABLE(5, s);
Ask w(rect(10, 10, 50, 13), "demo.db", fields, "window.pcy", 0);
w.show_window();
w.exe();
w.hide();
close_KNOW_HOW();
closegraph();
}